package com.easyhouse.service;

import com.easyhouse.common.pojo.Cart;
import com.easyhouse.common.pojo.Product;
import com.easyhouse.mapper.CartMapper;
import com.easyhouse.user.UserApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {
    @Autowired
    private UserApi userApi;
    @Autowired(required = false)
    private CartMapper cartMapper;
    @Override
    public List<Product> queryProductsByUserId(String userId) {
        String userName = userApi.queryByUserId(userId);
        List<Product> products = cartMapper.queryProductsByUserId(userName);
        return products;
    }

    @Override
    public void buyPrduct(String userId, String productId) {
        String userName = userApi.queryByUserId(userId);
        cartMapper.updateProduct(userName,productId);
    }
}
